package com.yyb.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.yyb.enums.ResultEnums;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * 描述: [公共的返回类]
 * 
 * 
 */
@Data
@Schema(name = "统一的返回对象")
public class Result<T> {

    @Schema(title = "状态码",example = "2000")
    private Integer code;

    @Schema(title = "状态消息",example = "操作成功")
    private String msg;

    @Schema(title = "数据")
    @JsonInclude(value = JsonInclude.Include.NON_NULL)
    private T data;

    public Result() {
        this.code= ResultEnums.SUCCESS.getCode();
        this.msg= ResultEnums.SUCCESS.getMsg();
    }

    public Result(String msg) {
        this.code= ResultEnums.SUCCESS.getCode();
        this.msg= msg;
    }

    public Result(T data) {
        this.code= ResultEnums.SUCCESS.getCode();
        this.msg= ResultEnums.SUCCESS.getMsg();
        this.data=data;
    }
    public Result(String msg,T data) {
        this.code= ResultEnums.SUCCESS.getCode();
        this.msg= msg;
        this.data=data;
    }

    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }
    public Result(ResultEnums resultEnums) {
        this.code=resultEnums.getCode();
        this.msg= resultEnums.getMsg();
    }

    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public Result(ResultEnums resultEnums,T data) {
        this.code=resultEnums.getCode();
        this.msg= resultEnums.getMsg();
        this.data=data;
    }
}
